
package com.android.launcher3;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.app.WallpaperManager;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.os.IBinder;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.Scroller;

import com.android.internal.util.XmlUtils;

public class QuickViewWorkspace extends FrameLayout implements View.OnLongClickListener,
                                                               View.OnClickListener {
    private Bitmap mDragBitmap;
    private Bitmap mPressBitmap;
    private Drawable mAddDrawable;
    private final Paint mDragPaint;
    private Drawable mScreenBgDrawable;
    private Drawable mScreenBgDrawable2;
    private Launcher mLauncher;
    private final Paint mTrashPaint;
    private Rect mScreenBgDrawablePadding;
    private Rect mScreenRect;
    private Rect mTmpRect;
    private TFAnimateEngine mAniEngine;
    private View mDeleteView;
    private View mDraggingView;
    private View mTouchedView;
    private WallpaperManager mWallpaperManager;
    private Animate[] mChildAnimate;
    private Rect[] mChildRects;
    private Rect[] mCurrentRects;
    private Rect[] mFinishRects;
    private Rect[] mStartRects;
    private Rect[] mTempRects;
    private int[] mTmpLocation;
    private int[] mTmpLocation2;
	private boolean mEnabledChildAnimation;
	private float mAnimationDuration;
    private float mLastMotionX;
    private float mLastMotionY;
    private int mAnimationState;
    private int mCurrentPage;
    private int mDeleteIndex;
    private int mDragState;
    private int mDraggingIndex;
    private int mOriginDragIndex;
    private int mPinchIndex;
    private int mTouchSlop;
    private int mTouchState;
    private int mWorkspaceScreenCountOnOpen;
    private int mWorkspaceScreenIndexOnOpen;
    private long mAnimationStartTime;
    private static final Object ADD_BTN_TAG = new Object();
    public static final int ANIMATION_IN_TIME = 400;
    public static final int ANIMATION_OUT_TIME = 300;
    private static final int ANIMATION_STATE_OPEN_STARTING = 1;
    private static final int ANIMATION_STATE_OPEN_RUNNING = 2;
    private static final int ANIMATION_STATE_OPEN_DONE = 7;
    private static final int ANIMATION_STATE_CLOSE_STARTING = 3;
    private static final int ANIMATION_STATE_CLOSE_RUNNING = 4;
    private static final int ANIMATION_STATE_CLOSE_DONE = 8;
    static final int INVALID_VALUE = 255;
    private static final String TAG_QUICKVIEW = "quickview";
    private static final String TAG_QUICKVIEWLAYOUT = "quickviewlayout";
    private static final String TAG_QUICKVIEWSET = "quickviewset";
    static final int TOUCH_DRAG_DELETE = 1;
    static final int TOUCH_DRAG_NORMAL = 0;
    static final int TOUCH_STATE_REST = 0;
    static final int TOUCH_STATE_SCROLLING = 1;
    static final int TOUCH_STATE_DRAGGING = 2;
    static final int TOUCH_STATE_PINCHOUT = 3;
    static final int TOUCH_STATE_PINCHIN = 4;
    private static final String TAG = "QuickViewWorkspace";

    /**
     * Creates a new QuickViewWorkspace object.
     */
    public QuickViewWorkspace(final Context context) {
        this(context, null);
    }

    /**
     * Creates a new QuickViewWorkspace object.
     */
    public QuickViewWorkspace(final Context context,
                              final AttributeSet attrs) {
        this(context, attrs, 0);
    }

    /**
     * Creates a new QuickViewWorkspace object.
     */
    public QuickViewWorkspace(final Context context,
                              final AttributeSet attrs,
                              final int defStyle) {
        super(context, attrs, defStyle);
        this.mChildAnimate = new Animate[Launcher.SCREEN_COUNT];
        this.mTmpRect = new Rect();
        this.mScreenRect = new Rect();
        this.mTouchState = TOUCH_STATE_REST;
        this.mDragState = TOUCH_DRAG_NORMAL;
        this.mDragBitmap = null;
        this.mPressBitmap = null;
        this.mScreenBgDrawablePadding = new Rect();
        this.mTrashPaint = new Paint();
        this.mDragPaint = new Paint();
        this.mAnimationState = ANIMATION_STATE_OPEN_DONE;
        this.mTmpLocation = new int[4];
        this.mTmpLocation2 = new int[4];
        init();
    }

    /**
     * 完整
     */
    public void drawCloseAnimation() {
        if (this.mAnimationState == ANIMATION_STATE_OPEN_DONE) {
            this.mAnimationState = ANIMATION_STATE_CLOSE_STARTING;
            this.mAnimationDuration = ANIMATION_OUT_TIME;
        }
    }

    /**
     * 完整
     */
    public void drawOpenAnimation() {
        this.mAnimationState = ANIMATION_STATE_OPEN_STARTING;
        this.mAnimationDuration = ANIMATION_IN_TIME;
    }

    /**
     * 完整
     *
     * @return
     */
    public int getCurrentPage() {
        return this.mCurrentPage;
    }

    public int getDeleteIndex() {
        return this.mDeleteIndex;
    }

    public boolean isAnimating() {
        if ((this.mAnimationState == ANIMATION_STATE_OPEN_DONE)
                || (this.mAnimationState == ANIMATION_STATE_CLOSE_DONE)) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 完整.
     */
    public void onClick(final View v) {
        Object localObject1 = v.getTag();

        if (localObject1 != ADD_BTN_TAG) {
            this.mCurrentPage = ((Integer) v.getTag()).intValue();
            drawCloseAnimation();
            postInvalidate();

            return;
        } else {
            addScreen();
        }
    }

    public boolean onInterceptTouchEvent(final MotionEvent event) {
        int action = event.getAction();
        float x = event.getX();
        float y = event.getY();

        if ((this.mAnimationState != ANIMATION_STATE_OPEN_DONE)
                && (this.mAnimationState != ANIMATION_STATE_CLOSE_DONE)) {
            return true;
        }

        switch (action) {
        // 不需要滚动.
        case MotionEvent.ACTION_MOVE:

            // Log.e(TAG, "ACTION_MOVE");
            break;

        case MotionEvent.ACTION_DOWN: {
            // Log.e(TAG, "onInterceptTouchEvent  ACTION_DOWN");
            this.mLastMotionX = x;
            this.mLastMotionY = y;

            break;
        }

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            // Log.e(TAG, "onInterceptTouchEvent ACTION_UP");
            if (this.mTouchState == TOUCH_STATE_DRAGGING) {
                endDrag();

                return true;
            }

            break;
        }
        }

        return this.mTouchState != TOUCH_STATE_REST;
    }

    public boolean onLongClick(final View view) {
        if (this.mLauncher.isWorkspaceLocked()) {
            Log.d("QuickViewWorkspace",
                  "ignoring long click. Desktop is loading. Editing not allowed.");

            return false;
        } else {
            Object localObject1 = view.getTag();
            Object localObject2 = ADD_BTN_TAG;

            if ((localObject1 != localObject2) && (getChildCount() > 2)) {
                startDrag(view);
            }

            return false;
        }
    }

    public boolean onTouchEvent(final MotionEvent event) {
        int action = event.getAction();
        float x = event.getX();
        float y = event.getY();

        if ((this.mAnimationState != ANIMATION_STATE_OPEN_DONE)
                && (this.mAnimationState != ANIMATION_STATE_CLOSE_DONE)) {
            return false;
        }

        switch (action) {
        // case 0:
        case MotionEvent.ACTION_DOWN: {
            // Log.e(TAG, "onTouchEvent ACTION_DOWN  ");
            this.mLastMotionX = x;
            this.mLastMotionY = y;

            break;
        }

        // case 2:
        case MotionEvent.ACTION_MOVE: {
            // Log.e(TAG, "onTouchEvent ACTION_MOVE  ");
            int deltaX = (int) (this.mLastMotionX - x);
            int deltaY = (int) (this.mLastMotionY - y);

            //			Log.e(TAG, "deltaY   " + deltaY);

            //			if (Math.abs(deltaY) > this.mTouchSlop
            //					&& this.mTouchState == TOUCH_STATE_DRAGGING) {
            if (this.mTouchState == TOUCH_STATE_DRAGGING) {
                // Log.e(TAG,
                // "onTouchEvent ACTION_MOVE   TOUCH_STATE_DRAGGING ");
                View localView1 = this.mDraggingView;

                if (localView1 != null) {
                    Rect localRect = this.mTmpRect;
                    localView1.getHitRect(localRect);
                    localRect.left = localRect.left - deltaX;
                    localRect.top = localRect.top - deltaY;
                    localRect.right = localRect.right - deltaX;
                    localRect.bottom = localRect.bottom - deltaY;

                    int i6 = localRect.left;
                    int i7 = localRect.top;
                    int i8 = localRect.right;
                    int i9 = localRect.bottom;
                    localView1.layout(i6, i7, i8, i9);
                }

                View localView2 = this.mDraggingView;
                int i10 = (int) x;
                int i11 = (int) y;
                int i12 = getTouchedIndex(i10, i11);

                if (i12 != -1) {
                    int i13 = this.mDraggingIndex;

                    if (i12 != i13) {
                        Object localObject1 = getChildAt(i12).getTag();
                        Object localObject2 = ADD_BTN_TAG;

                        if (localObject1 != localObject2) {
                            removeView(localView2);
                            addView(localView2, i12);
                            localView2.setVisibility(View.INVISIBLE);
                            this.mDraggingIndex = i12;
                        }
                    }
                }

                int i14 = (int) x;
                int i15 = (int) y;

                if (isDeleteZone(i14, i15)) {
                    applyDeleteZone();
                    setDeleteZoneState(true);
                }

                // break;
            }

            if ((this.mDraggingView != null) || (this.mTouchedView != null)) {
                postInvalidate();
            }

            this.mLastMotionX = x;
            this.mLastMotionY = y;

            return true;
        }

        // case 1:
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            // Log.e(TAG, "onTouchEvent ACTION_UP");
            if (this.mTouchState == TOUCH_STATE_DRAGGING) {
                int i19 = (int) x;
                int i20 = (int) y;
                drop(i19, i20);
            }

            if ((this.mDraggingView != null) || (this.mTouchedView != null)) {
                postInvalidate();
            }

            endDrag();

            break;
        }
        }

        return true;
    }

    /**
     * 完整
     */
    public void removeScreen() {
        //		Log.e(TAG,"removeScreen");

        if ((indexOfChild(this.mDeleteView) == -1) || (this.mDeleteView == null)) {
            this.mDeleteView = null;
            return;
        }
        removeView(this.mDeleteView);

        int i = getChildCount();

        if (i >= 1) {
            int j = i - 1;
            if (getChildAt(j).getTag() != ADD_BTN_TAG) {
                makeAddBtn();
            }
        } else {
            makeAddBtn();
        }

        onRemove();

        this.mCurrentPage = this.mLauncher.getWorkspace().getCurrentScreen();
    }

    protected void dispatchDraw(final Canvas canvas) {
//        		Log.e(TAG,"dispatchDraw");
        int i = getChildCount();
        long l1 = getDrawingTime();

        if ((getWidth() == 0) || (getHeight() == 0)) {
            return;
        }

        this.mLauncher.getMenuDrawer().setEnabledProgress(false);

        // Log.e(TAG,"111111111  mAnimationState "+ mAnimationState);
        if (this.mAnimationState == ANIMATION_STATE_OPEN_STARTING) {
            // Log.e(TAG,"ANIMATION_STATE_OPEN_STARTING  111111111111");
            this.mAnimationStartTime = SystemClock.uptimeMillis();
            this.mAnimationState = ANIMATION_STATE_OPEN_RUNNING;
            this.mPinchIndex = this.mLauncher.getWorkspace().getCurrentScreen();
            this.setOpenStartRect(this.mPinchIndex);
            requestLayout();
            this.mFinishRects = new Rect[i];
            this.mCurrentRects = new Rect[i];
            int i3 = 0;
            while (i3 < i) {
                this.mFinishRects[i3] = new Rect();
                this.mFinishRects[i3].set(this.mChildRects[i3]);
                this.mCurrentRects[i3] = new Rect();
                i3++;
            }
        }

        if (this.mAnimationState == ANIMATION_STATE_CLOSE_STARTING) {
            //			Log.e(TAG, "ANIMATION_STATE_CLOSE_STARTING  111111111111");
            this.mAnimationStartTime = SystemClock.uptimeMillis();
            this.mAnimationState = ANIMATION_STATE_CLOSE_RUNNING;
            this.mPinchIndex = this.mCurrentPage;
            requestLayout();
            this.setCloseEndRect(this.mPinchIndex);
            this.mStartRects = new Rect[i];
            this.mCurrentRects = new Rect[i];
            int i3 = 0;
            while (i3 < i) {
                mStartRects[i3] = new Rect();
                mStartRects[i3].set(this.mChildRects[i3]);
                this.mCurrentRects[i3] = new Rect();
                i3++;
            }
        }

        View localView1;

        if (this.mTouchState == TOUCH_STATE_DRAGGING) {
            // Log.e(TAG, "TOUCH_STATE_DRAGGING  TOUCH_STATE_DRAGGING");
            int i3 = 0;
            while (i3 < i) {
                localView1 = this.getChildAt(i3);
                if (localView1 != this.mDraggingView) {
                    this.drawChild(canvas, localView1, l1);
                }
                i3++;
            }

            float f1 = this.mScrollX;
            float f2 = this.mScrollY;
            float f3 = this.mScrollX + getWidth();
            float f4 = this.mScrollY + getHeight();
            Region.Op localOp1 = Region.Op.REPLACE;
            canvas.clipRect(f1, f2, f3, f4, localOp1);
            this.drawChild(canvas, this.mDraggingView, l1);
            // postInvalidate();
            return;

            // continue;
        }

        if ((this.mAnimationState == ANIMATION_STATE_OPEN_RUNNING)
                || (this.mAnimationState == ANIMATION_STATE_CLOSE_RUNNING)) {
            // if (this.mAnimationState == ANIMATION_STATE_OPEN_RUNNING) {
            // Log.e(TAG,
            // "this.mAnimationState == ANIMATION_STATE_OPEN_RUNNING ");
            // }
            long l6 = SystemClock.uptimeMillis();
            long l7 = this.mAnimationStartTime;
            float i15 = (l6 - l7);

            // 动画是否已经完成.
            if (i15 >= this.mAnimationDuration) {
                i15 = this.mAnimationDuration;

                if (this.mAnimationState == ANIMATION_STATE_CLOSE_RUNNING) {
                    this.mLauncher.closeQuickViewWorkspace();
                }
            }

            float f6 = this.mAnimationDuration;
            float f7 = i15 / f6;

            if (this.mAnimationState == ANIMATION_STATE_CLOSE_RUNNING) {
                int i18 = this.mLauncher.getWorkspace().getCurrentScreen();

                if (this.mPinchIndex != i18) {
                    this.updateWallpaperOffset(this.mPinchIndex,
                                               this.mLauncher.getWorkspace()
                                                             .getChildCount(),
                                               f7);
                }
            }

            if (i15 >= this.mAnimationDuration) {
                if (this.mAnimationState == ANIMATION_STATE_OPEN_RUNNING) {
                    this.mAnimationState = ANIMATION_STATE_OPEN_DONE;
                }
            }
            // 动画继续
            else {
                if ((this.mCurrentRects == null)
                        || (this.mCurrentRects.length != i)) {
                    if (i > 0) {
                        this.mCurrentRects = new Rect[i];
                    }
                }

                // mStartRects 中放置的是 每个孩子开始做动画时的起始的坐标值,
                // mFinishRects中放置的是每个孩子在执行完动画之后最终在屏幕上的坐标值.
                // mCurrentRects 是执行运算之后的值，用它来显示孩子在屏幕上.
                // mChildRects 中放置的是 在配置文件中配置的每个孩子在屏幕上的坐标值,不会再被赋于其它值.
                this.mCurrentRects = this.mAniEngine.getRect(this.mStartRects,
                                                             this.mFinishRects,
                                                             this.mCurrentRects,
                                                             f7);

//                int d = this.mStartRects[mPinchIndex].left;
//
//                int dd = this.mFinishRects[mPinchIndex].left;

                // Log.e(TAG, "3333333333 mStartRects  " + (d));
                //
                // Log.e(TAG, "3333333333 mFinishRects  " + (dd));
                //
                // Log.e(TAG, "3333333333 dddd " + (dd - d));
                //
                // Log.e(TAG, "3333333333 f7 " + f7);

                // postInvalidate();
                for (int j = 0; j < i; j++) {
                    if (j != mPinchIndex) {
                        View localView9 = this.getChildAt(j);
                        Drawable localDrawable1 = this.mScreenBgDrawable;
                        localView9.setBackgroundDrawable(localDrawable1);

                        int i8 = this.mCurrentRects[j].left;
                        int i9 = this.mCurrentRects[j].top;
                        int i10 = this.mCurrentRects[j].right;
                        int i11 = this.mCurrentRects[j].bottom;
                        localView9.layout(i8, i9, i10, i11);

                        if (isAvailableRect(this.mCurrentRects[j])) {
                            this.drawChild(canvas, localView9, l1);
                        }
                    }
                }

                // 执行由大到小的动画
                if ((this.mPinchIndex >= 0) && (this.mPinchIndex < i)) {
                    float f14 = this.mCurrentRects[mPinchIndex].left;
                    float f15 = this.mCurrentRects[mPinchIndex].top;
                    float f16 = this.mCurrentRects[mPinchIndex].right;
                    float f17 = this.mCurrentRects[mPinchIndex].bottom;
                    canvas.clipRect(f14, f15, f16, f17, Region.Op.REPLACE);
                    // Log.e(TAG, "333333333333333333   mPinchIndex view  left "
                    // + f14);
                    // Log.e(TAG,"mPinchIndex view  right "+ f16);
                    this.getChildAt(mPinchIndex)
                        .layout((int) f14, (int) f15, (int) f16, (int) f17);
                    this.getChildAt(mPinchIndex)
                        .setBackgroundDrawable(mScreenBgDrawable);
                    this.drawChild(canvas, this.getChildAt(mPinchIndex), l1);
                }

                postInvalidate();

                return;
            }
        }

        for (int j = 0; j < i; j++) {
            View localView9 = this.getChildAt(j);
            localView9.setBackgroundDrawable(this.mScreenBgDrawable);
            this.drawChild(canvas, localView9, l1);
        }
    }

    /**
     * 完整
     */
    protected boolean drawChild(final Canvas canvas, final View view,
                                final long paramLong) {
        		Log.e(TAG,"drawChild "+view.toString());
        float f3;
        float f4;
        float f13;
        float f17;

        // 正在做动画
        if (this.mAnimationState == ANIMATION_STATE_OPEN_RUNNING
                || this.mAnimationState == ANIMATION_STATE_CLOSE_RUNNING
                || this.mAnimationState == ANIMATION_STATE_OPEN_DONE) {
            long l1 = SystemClock.uptimeMillis();
            long l2 = this.mAnimationStartTime;
            float f1 = (int) (l1 - l2);
            float f2 = this.mAnimationDuration;
            f3 = f1 / f2;

            if (this.mAnimationState == ANIMATION_STATE_OPEN_RUNNING) {
                f4 = f3;
            } else if (this.mAnimationState == ANIMATION_STATE_CLOSE_RUNNING) {
                f4 = 1.0F - f3;
            } else {
                f4 = 1.0f;
            }

            float f5 = 1.0F;
            float f6 = f4;
            float f7 = Math.min(f5, f6);
            float f8 = 0.0F;
            float f9 = f7;
            float f10 = Math.max(f8, f9);
            int i2 = (int) (255.0F * f10);
            this.mScreenBgDrawable2.setAlpha(i2);

            //			Log.e(TAG, "Alpha " + i2);
            int i3 = view.getLeft();
            int i4 = view.getTop();
            int i5 = view.getRight();
            int i6 = view.getBottom();
            this.mScreenBgDrawable2.setBounds(i3, i4, i5, i6);
            this.mScreenBgDrawable2.draw(canvas);

            Object localObject1 = view.getTag();

            // 对add button的处理
            if ((localObject1 == ADD_BTN_TAG) || (this.mLauncher == null)
                    || (!(localObject1 instanceof Integer))) {
                int i34 = this.mAddDrawable.getIntrinsicWidth();
                int i35 = this.mAddDrawable.getIntrinsicHeight();
                this.mAddDrawable.setAlpha(i2);

                int i36 = view.getLeft();
                int i37 = (view.getWidth() - i34) / 2;
                int i38 = i36 + i37;
                int i39 = view.getTop();
                int i40 = (view.getHeight() - i35) / 2;
                int i41 = i39 + i40;
                Drawable localDrawable4 = this.mAddDrawable;
                int i42 = i38 + i34;
                int i43 = i41 + i35;
                Drawable localDrawable5 = localDrawable4;
                int i44 = i38;
                int i45 = i41;
                int i46 = i42;
                int i47 = i43;
                localDrawable5.setBounds(i44, i45, i46, i47);

                Drawable localDrawable6 = this.mAddDrawable;
                Canvas localCanvas6 = canvas;
                localDrawable6.draw(localCanvas6);
            } else {
                int i7 = ((Integer) localObject1).intValue();
                Workspace localWorkspace = this.mLauncher.getWorkspace();
                int i8 = i7;
                View localView1 = localWorkspace.getChildAt(i8);

                if (localView1 != null) {
                    canvas.save();

                    int i10 = view.getHeight();
                    int i11 = view.getPaddingLeft();
                    int i12 = i10 - i11;
                    int i13 = view.getPaddingRight();
                    float f11 = i12 - i13;
                    float f12 = localView1.getHeight();
                    f13 = f11 / f12;

                    int i14 = view.getWidth();
                    int i15 = view.getPaddingTop();
                    int i16 = i14 - i15;
                    int i17 = view.getPaddingBottom();
                    float f14 = i16 - i17;
                    float f15 = localView1.getWidth();
                    float f16 = f14 / f15;

                    if (f13 <= f16) {
                        f17 = f13;
                    } else {
                        f17 = f16;
                    }

                    Rect localRect1 = this.mTmpRect;
                    int i18 = view.getPaddingLeft();
                    localRect1.left = i18;

                    Rect localRect2 = this.mTmpRect;
                    int i19 = view.getPaddingTop();
                    localRect2.top = i19;

                    Rect localRect3 = this.mTmpRect;
                    int i20 = view.getWidth();
                    int i21 = view.getPaddingRight();
                    int i22 = i20 - i21;
                    localRect3.right = i22;

                    Rect localRect4 = this.mTmpRect;
                    int i23 = view.getHeight();
                    int i24 = view.getPaddingBottom();
                    int i25 = i23 - i24;
                    localRect4.bottom = i25;

                    int i26 = (int) (localView1.getWidth() * f17);
                    int i27 = (int) (localView1.getHeight() * f17);
                    Rect localRect5 = this.mTmpRect;
                    Rect localRect6 = this.mTmpRect;
                    Gravity.apply(17, i26, i27, localRect5, localRect6);

                    int i28 = this.mTmpRect.left;
                    int i29 = this.mTmpRect.top;
                    float f18 = view.getLeft() + i28;
                    float f19 = view.getTop() + i29;
                    Canvas localCanvas2 = canvas;
                    float f20 = f18;
                    float f21 = f19;
                    localCanvas2.translate(f20, f21);

                    Canvas localCanvas3 = canvas;
                    float f22 = f17;
                    float f23 = f17;
                    localCanvas3.scale(f22, f23);

                    View localView2 = localView1;
                    Canvas localCanvas4 = canvas;
                    localView2.draw(localCanvas4);
                    canvas.restore();
                }
            }

            View localView3 = this.mTouchedView;
            View localView4 = view;

            if (localView3 == localView4) {
                if (this.mDragState == TOUCH_DRAG_DELETE) {
                    Bitmap localBitmap1 = this.mDragBitmap;
                    float f24 = view.getLeft();
                    float f25 = view.getTop();
                    Paint localPaint1 = this.mTrashPaint;
                    Canvas localCanvas5 = canvas;
                    Bitmap localBitmap2 = localBitmap1;
                    float f26 = f24;
                    float f27 = f25;
                    Paint localPaint2 = localPaint1;
                    localCanvas5.drawBitmap(localBitmap2, f26, f27, localPaint2);
                } else {
                    Bitmap localBitmap3 = this.mPressBitmap;
                    float f28 = view.getLeft();
                    float f29 = view.getTop();
                    Paint localPaint3 = this.mDragPaint;
                    Canvas localCanvas7 = canvas;
                    Bitmap localBitmap4 = localBitmap3;
                    float f30 = f28;
                    float f31 = f29;
                    Paint localPaint4 = localPaint3;
                    localCanvas7.drawBitmap(localBitmap4, f30, f31, localPaint4);
                }
            }

            return false;
        } else {
            return super.drawChild(canvas, view, paramLong);
        }
    }

    /**
     * 完整
     */
    protected void onLayout(final boolean changed, final int left,
                            final int top, final int right, final int bottom) {
//         Log.e(TAG, "onLayout");
        int childCount = getChildCount();
        
//        Log.e(TAG, "childCount "+childCount);
        
        if (childCount == 0) {
            return;
        }

        if ((this.mChildRects == null)
                || (this.mChildRects.length != childCount)) {
            this.mChildRects = new Rect[childCount];
        }

        getViewLayout(childCount);
        
//        Log.e(TAG, "childCount "+childCount);

        int j = 0;
        View localView;

        while (j < childCount) {
            localView = getChildAt(j);

            Rect localRect1 = new Rect();

            if (localView.getVisibility() != View.GONE) {
                if (this.mChildRects[j] == null) {
                    mChildRects[j] = new Rect();
                }
//                Log.e(TAG, ""+this.mTempRects.length +"  " + j);
                
                this.mChildRects[j].set(this.mTempRects[j]);
                localView.getHitRect(localRect1);

                if ((localRect1.isEmpty()) || (!this.mEnabledChildAnimation)) {
                    int k = this.mChildRects[j].left;
                    int m = this.mChildRects[j].top;
                    int n = this.mChildRects[j].right;
                    int i1 = this.mChildRects[j].bottom;
                    localView.layout(k, m, n, i1);
                } else {
                    if (localView.getVisibility() == View.VISIBLE) {
                        Animate localAnimate = this.mChildAnimate[j];
                        localAnimate.start(localView, this.mChildRects[j]);
                    }
                }
            }

            j++;
        }
    }

    /**
     * 完整
     */
    void cancelDeleteView() {
        if (this.mDeleteView == null) {
            return;
        }

        removeView(this.mDeleteView);
        addView(this.mDeleteView, this.mDeleteIndex);
        this.mDeleteIndex = -1;
        this.mDeleteView = null;
        this.mDragState = TOUCH_DRAG_NORMAL;
    }

    void cancelDrag() {
        // Log.e(TAG,"cancelDrag");
        if (this.mDraggingView != null) {
            this.mDraggingView.setVisibility(View.VISIBLE);
            removeView(this.mDraggingView);
            int i = this.mOriginDragIndex;
            addView(this.mDraggingView, i);
            this.mDraggingView.requestLayout();
        }

        updateTag();
        setDeleteZoneState(false);
        this.mDragState = TOUCH_DRAG_NORMAL;
        this.mTouchState = TOUCH_STATE_REST;
        this.mDraggingIndex = -1;
        this.mDraggingView = null;
        this.mTouchedView = null;
        this.mPinchIndex = -1;
        this.mOriginDragIndex = -1;
        postInvalidate();
    }

    /**
     * 完整
     */
    void close() {
        this.mScrollY = 0;
        this.mEnabledChildAnimation = false;
        this.mLauncher.getDeleteZone().setVisibility(View.INVISIBLE);
        setVisibility(View.INVISIBLE);
        disableWorkspaceScreensCache();
    }

    /**
     * 完整
     */
    void disableWorkspaceScreensCache() {
        Workspace localWorkspace = this.mLauncher.getWorkspace();
        int i = localWorkspace.getChildCount();
        int j = 0;

        while (j < i) {
            ((CellLayout) localWorkspace.getChildAt(j))
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               .setChildrenDrawnWithCacheEnabled(false);
            j++;
        }
    }

    /**
     * 完整
     *
     * @param index
     */
    void initScreen(final int index) {
        // Log.e(TAG, "initScreen " + paramInt);
        removeAllViews();
        setBackgroundResource(0);

        int k = 0;

        while (k < index) {
            makeScreen(k);
            k++;
        }

        int m = Launcher.SCREEN_COUNT;
        if (index < m) {
            makeAddBtn();
        }
        getGlobalVisibleRect(this.mScreenRect);
    }

    boolean isOpened() {
        return (getVisibility() == View.VISIBLE);
    }

    void open() {
    	
    	long start=System.currentTimeMillis();
        this.mEnabledChildAnimation = true;
        this.mCurrentPage = this.mLauncher.getWorkspace().getCurrentScreen();
        DeleteZone localDeleteZone = this.mLauncher.getDeleteZone();
        localDeleteZone.setVisibility(View.VISIBLE);
        localDeleteZone.resetMode();
        this.mWorkspaceScreenCountOnOpen = this.mLauncher.getWorkspace()
                                                         .getChildCount();
        this.mWorkspaceScreenIndexOnOpen = this.mCurrentPage;
//        enableWorkspaceScreensCache();
        
        setVisibility(View.VISIBLE);
        Log.e(TAG, "open took "+(System.currentTimeMillis()-start) +"ms");
    }
    
    
    
    /**
     * 完整
     *
     * @param paramLauncher
     */
    void setLauncher(final Launcher paramLauncher) {
        this.mLauncher = paramLauncher;
    }

    private void addScreen() {
        int i = getChildCount();
        if (i == Launcher.SCREEN_COUNT) {
            this.removeViewAt(i - 1);
        }
        makeScreen(i - 1).setOnLongClickListener(this);
        onAdd();
    }

    private void applyDeleteZone() {
        this.mDragState = TOUCH_DRAG_DELETE;
        this.mDraggingView.buildDrawingCache();
        Bitmap localBitmap1 = this.mDraggingView.getDrawingCache();
        int i = localBitmap1.getWidth();
        int j = localBitmap1.getHeight();
        Matrix localMatrix = new Matrix();
        localMatrix.setScale(1.0F, 1.0F);
        this.mDragBitmap = Bitmap.createBitmap(localBitmap1, 0, 0, i, j,
                                               localMatrix, true);
    }

    private void drop(final int x, final int y) {
        this.mDraggingView.setVisibility(View.VISIBLE);
        this.mDraggingView.requestLayout();

        if ((isDeleteZone(x, y)) && (this.mDragState == TOUCH_DRAG_DELETE)) {
            removeView(this.mDraggingView);

            int i = this.mDraggingIndex;
            addView(this.mDraggingView, i);

            int j = this.mDraggingIndex;
            swapScreen(j);

            int k = this.mDraggingIndex;
            this.mDeleteIndex = k;
            this.mDeleteView = this.mDraggingView;
            setDeleteZoneState(false);
            if (isIncludeItem()) {
                this.mLauncher.showDeleteWorkScreen();
                return;
            } else {
                removeScreen();
                return;
            }
        } else {
            int m = getTouchedIndex(x, y);
            if (m != -1) {
                if (getChildAt(m).getTag() != ADD_BTN_TAG) {
//                	Log.e(TAG,"start swapScreen  !ADD_BTN_TAG");
                    swapScreen(m);
                    return;
                }
            } else {
                swapScreen(this.mDraggingIndex);
            }
        }
    }

    private void enableWorkspaceScreensCache() {
        Workspace localWorkspace = this.mLauncher.getWorkspace();
        int i = localWorkspace.getChildCount();
        int j = 0;

        while (j < i) {
            CellLayout localCellLayout = (CellLayout) localWorkspace.getChildAt(j);
            localCellLayout.setChildrenDrawingCacheEnabled(true);
            localCellLayout.setChildrenDrawnWithCacheEnabled(true);
            j++;
        }
    }

    /**
     * 完整
     */
    private void endDrag() {
        //		Log.e(TAG, "endDrag");
        this.mTouchState = TOUCH_STATE_REST;
        this.mDragState = TOUCH_DRAG_NORMAL;
        this.mDraggingView = null;
        this.mTouchedView = null;
        this.mPinchIndex = -1;
        this.mDraggingIndex = -1;
        this.mOriginDragIndex = -1;
    }

    /**
     * 完整
     *
     * @param x
     * @param y
     *
     * @return
     */
    private int getTouchedIndex(final int x, final int y) {
        if (this.mChildRects == null) {
            return -1;
        } else {
            int j = this.mChildRects.length;
            int k = 0;

            while (k < j) {
                if (this.mChildRects[k] == null) {
                    k++;

                    continue;
                }

                Rect localRect;
                int m;
                int n;
                localRect = this.mChildRects[k];
                m = this.mScrollX + x;
                n = this.mScrollY + y;

                if (localRect.contains(m, n)) {
                    return k;
                } else {
                    k++;
                }
            }
        }

        return -1;
    }

    /**
     * 取得每个孩子的位置坐标并放置在 this.mTempRects
     *
     * @param index
     */
    private void getViewLayout(final int index) {
    	
//    	Log.e(TAG,"getViewLayout"+ index);
    	
        this.mTempRects = new Rect[index];

        try {
            XmlResourceParser localXmlResourceParser1 = this.mContext.getResources()
                                                                     .getXml(R.xml.quickview_layout);
            XmlUtils.beginDocument(localXmlResourceParser1, TAG_QUICKVIEWLAYOUT);

            int i = localXmlResourceParser1.getDepth();

            while (true) {
                int k = localXmlResourceParser1.next();

                if (((k == XmlPullParser.END_TAG)
                        && (localXmlResourceParser1.getDepth() <= i))
                        || (k == XmlPullParser.END_DOCUMENT)) {
                    break;
                }

                if (k != XmlPullParser.START_TAG) {
                    continue;
                }

                String str = localXmlResourceParser1.getName();

                if (!TAG_QUICKVIEWSET.equals(str)) {
                    continue;
                }

                int count = Integer.parseInt(localXmlResourceParser1
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        .getAttributeValue(0));

                if (count == index) {
                    int c = 0;
//                  	Log.e(TAG,"c111 "+ c);
                    int width = Integer.parseInt(localXmlResourceParser1
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              .getAttributeValue(1));

                    int height = Integer.parseInt(localXmlResourceParser1
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 .getAttributeValue(2));

                    while (c < count) {
//                       	Log.e(TAG,"c "+ c);
                        int type = localXmlResourceParser1.next();

                        if (type == XmlPullParser.START_TAG
                                && localXmlResourceParser1.getName()
                                                              .equals(TAG_QUICKVIEW)) {
                            if (this.mTempRects[c] == null) {
                                this.mTempRects[c] = new Rect();
                            }

                            int left = Integer.parseInt(localXmlResourceParser1
                                                        .getAttributeValue(0));
                            int top = Integer.parseInt(localXmlResourceParser1
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                .getAttributeValue(1));
                            this.mTempRects[c].set(left, top, left + width,
                                                   top + height);
                            c++;
                        }
                    }
                }
            }
        } catch (final XmlPullParserException e) {
            e.printStackTrace();
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 完整
     */
    private void init() {
    	
        this.mWallpaperManager = WallpaperManager.getInstance(getContext());

        this.mAniEngine = new TFAnimateEngine();

        this.mAniEngine.setInterpolator(new AccelerateDecelerateInterpolator());

        // this.mOrientation = getResources().getConfiguration().orientation;
        Context localContext = getContext();
        this.mTouchSlop = ViewConfiguration.get(localContext)
                                           .getScaledTouchSlop();

        int k = localContext.getResources()
                            .getColor(R.color.delete_color_filter2);

        PorterDuffColorFilter localPorterDuffColorFilter1 = new PorterDuffColorFilter(k,
                                                                                      PorterDuff.Mode.SRC_ATOP);

        this.mTrashPaint.setColorFilter(localPorterDuffColorFilter1);

        int m = localContext.getResources()
                            .getColor(R.color.quickview_drag_color_filter);

        PorterDuffColorFilter localPorterDuffColorFilter2 = new PorterDuffColorFilter(m,
                                                                                      PorterDuff.Mode.SRC_ATOP);
        mDragPaint.setColorFilter(localPorterDuffColorFilter2);

        int n = 0;
        int i1 = Launcher.SCREEN_COUNT;

        while (n < i1) {
            this.mChildAnimate[n] = new Animate();
            n++;
        }

        setClipChildren(false);
        
        
        Resources localResources = getContext().getResources();
        this.mScreenBgDrawable = localResources.getDrawable(R.drawable.quicknavigation_background);
        this.mScreenBgDrawable.getPadding(this.mScreenBgDrawablePadding);

        this.mScreenBgDrawable2 = localResources.getDrawable(R.drawable.quicknavigation_background)
                                                .mutate();

        this.mAddDrawable = localResources.getDrawable(R.drawable.homescreen_quick_navigation_add);
        
    }

    /**
     * 完整
     *
     * @param rect
     *
     * @return
     */
    private boolean isAvailableRect(final Rect rect) {
        int i = rect.right;
        int j = this.mScreenRect.left;

        if (i >= j) {
            int k = rect.top;
            int m = this.mScreenRect.bottom;

            if (k <= m) {
                int n = rect.left;
                int i1 = this.mScreenRect.right;

                if (n <= i1) {
                    int i2 = rect.bottom;
                    int i3 = this.mScreenRect.top;

                    if (i2 >= i3) {
                        return true;
                    }
                }
            }
        }

        return false;
    }

    /**
     * 完整
     *
     * @param x
     * @param y
     *
     * @return
     */
    private boolean isDeleteZone(final int x, final int y) {
        //		Log.e(TAG,"isDeleteZone x "+x+"y "+y);
        DeleteZone localDeleteZone = this.mLauncher.getDeleteZone();
        localDeleteZone.getDeleteAreaRect(this.mTmpRect);
        localDeleteZone.getLocationOnScreen(this.mTmpLocation);
        getLocationInWindow(this.mTmpLocation2);

        //		Log.e(TAG,"mTmpRect  x "+mTmpRect.toShortString());
        //		Log.e(TAG,"mTmpLocation  x "+mTmpLocation[0]+" y "+mTmpLocation[1]);
        //		Log.e(TAG,"mTmpLocation2  x "+mTmpLocation2[0]+""+mTmpLocation2[1]);
        int k = this.mTmpLocation[0] - this.mTmpLocation2[0];
        int i1 = this.mTmpLocation[1] - this.mTmpLocation2[1];
        this.mTmpRect.offset(k, i1);
        //		Log.e(TAG,"mTmpRect  x "+mTmpRect.toShortString());
//        Log.e(TAG, "isDeleteZone " + this.mTmpRect.contains(x, y));

        return this.mTmpRect.contains(x, y);
    }

    /**
     * 判断要删除的屏幕中是否有子项.
     *
     * @return
     */
    private boolean isIncludeItem() {
        //		Log.e(TAG,"isIncludeItem");
        Workspace localWorkspace = this.mLauncher.getWorkspace();
        CellLayout localCellLayout = (CellLayout) localWorkspace.getChildAt(this.mDraggingIndex);
        int k = localCellLayout.getChildCount();
        for(int i=0;i<k;i++)
        {
            ItemInfo localItemInfo = (ItemInfo) localCellLayout.getChildAt(i)
                                                               .getTag();
            if (localItemInfo.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
                return true;
            }
        }
        return false;
    }

    /**
     * 完整
     *
     * @return
     */
    private View makeAddBtn() {
        // Log.e(TAG, "makeAddBtn ");
        View localView = makeScreen(getChildCount());
        localView.setTag(ADD_BTN_TAG);
        return localView;
    }

    /**
     * 完整
     *
     * @param index
     *
     * @return
     */
    private View makeScreen(final int index) {
        // Log.e(TAG, "makeScreen " + paramInt);
        View localView = new View(this.mContext);
        localView.setBackgroundDrawable(this.mScreenBgDrawable);
        addView(localView, index);
        localView.setTag(index);
        localView.setOnLongClickListener(this);
        localView.setOnClickListener(this);
        return localView;
    }

    /**
     * 完整
     */
    private void onAdd() {
        int i = getChildCount();
        Workspace localWorkspace = this.mLauncher.getWorkspace();
        CellLayout localCellLayout = (CellLayout) LayoutInflater.from(this.mLauncher)
                                                                .inflate(R.layout.workspace_screen,
                                                                         localWorkspace,
                                                                         false);
        localCellLayout.setOnLongClickListener(this.mLauncher);

        int j = this.mLauncher.getCellLayoutId(i);
        localCellLayout.setId(j);

        ViewGroup.LayoutParams localLayoutParams = localCellLayout
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               .getLayoutParams();

        if (localLayoutParams == null) {
            localLayoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                                                           ViewGroup.LayoutParams.FILL_PARENT);
        }

        localWorkspace.addView(localCellLayout, localLayoutParams);
        this.mLauncher.saveScreenInfo();
        updateTag();
    }

    /**
     * 测试验证
     */
    private void onRemove() {
        Workspace localWorkspace1 = this.mLauncher.getWorkspace();
        CellLayout localCellLayout = (CellLayout) localWorkspace1.getChildAt(this.mDeleteIndex);
        int j = localCellLayout.getChildCount();
        int k = 0;
        Object localObject1;
        ItemInfo localItemInfo1;

        while (k < j) {
            View localView1 = localCellLayout.getChildAt(k);
            localObject1 = localView1.getTag();

            if ((localView1 instanceof Folder)) {
                k += 1;

                continue;
            }

            localItemInfo1 = (ItemInfo) localObject1;

            if (localItemInfo1.container != -1) {
                // break;
            }

            if ((localItemInfo1 instanceof LauncherAppWidgetInfo)) {
                LauncherAppWidgetInfo localLauncherAppWidgetInfo1 = (LauncherAppWidgetInfo) localItemInfo1;
                this.mLauncher.removeAppWidget(localLauncherAppWidgetInfo1);

                LauncherAppWidgetHost localLauncherAppWidgetHost1 = this.mLauncher
                                                                    .getAppWidgetHost();

                if (localLauncherAppWidgetHost1 != null) {
                    localLauncherAppWidgetHost1.deleteAppWidgetId(localLauncherAppWidgetInfo1.appWidgetId);
                }
            }

            if ((localItemInfo1 instanceof ShortcutInfo)) {
                ShortcutInfo localShortcutInfo1 = (ShortcutInfo) localItemInfo1;
                this.mLauncher.removeShortcut(localShortcutInfo1);
            }

            if ((localItemInfo1 instanceof FolderInfo)) {
                FolderInfo localFolderInfo1 = (FolderInfo) localItemInfo1;
                this.mLauncher.removeFolder(localFolderInfo1);
            }

            if ((localItemInfo1 instanceof UserFolderInfo)) {
                UserFolderInfo localUserFolderInfo1 = (UserFolderInfo) localItemInfo1;
                LauncherModel.deleteUserFolderContentsFromDatabase(this.mLauncher,
                                                                   localUserFolderInfo1);
                this.mLauncher.removeFolder(localUserFolderInfo1);
            }

            if (localItemInfo1.container == -100) {
                LauncherModel.deleteItemFromDatabase(this.mLauncher,
                                                     localItemInfo1);
            }

            k++;
        }

        localWorkspace1.removeView(localCellLayout);
        updateAppInfoInDatabase();
        this.mLauncher.saveScreenInfo();
        this.mDeleteIndex = -1;
        this.mDeleteView = null;

        int i3 = localWorkspace1.getChildCount();

        if (i3 <= this.mLauncher.getWorkspace().getCurrentScreen()) {
            localWorkspace1.setCurrentScreen(i3 - 1);
            Launcher.setScreen(i3 - 1);
        }

        updateTag();
    }

    /**
     * 完整
     *
     * @param index
     */
    private void onSwap(final int index) {
        Workspace localWorkspace = this.mLauncher.getWorkspace();
        View localView = localWorkspace.getChildAt(this.mOriginDragIndex);
        int j = localWorkspace.indexOfChild(localView);
        Utilities.zOrderTweakMoveChild(localWorkspace, j, index, true);
        updateTag();
        updateAppInfoInDatabase();
        this.mLauncher.saveScreenInfo();
    }

    /**
     * 完整
     *
     * @param pinchIndex
     */
    private void setCloseEndRect(final int pinchIndex) {
        // Log.e(TAG, "setCloseEndRect");
        int i = getChildCount();
        this.getLocationOnScreen(this.mTmpLocation);

        View localView1 = this.mLauncher.getWorkspace().getChildAt(0);
        int i11 = 0;

        if (this.mFinishRects == null || this.mFinishRects.length != i) {
            this.mFinishRects = new Rect[i];

            while (i11 < i) {
                this.mFinishRects[i11] = new Rect();
                i11++;
            }
        }

        Rect localRect2 = this.mFinishRects[pinchIndex];

        int i12 = localView1.getLeft() - this.mScreenBgDrawablePadding.left;

        int i13 = localView1.getTop() - this.mScreenBgDrawablePadding.top;

        int i14 = localView1.getLeft() + localView1.getWidth()
                  + this.mScreenBgDrawablePadding.right;

        int i15 = localView1.getTop() + localView1.getHeight()
                  + this.mScreenBgDrawablePadding.bottom;

        localRect2.set(i12, i13, i14, i15);

        // localRect2.set(i12, 25, localView1.getWidth(),
        // localView1.getHeight());

        // Log.e(TAG,"pinchIndex  Rect "+localRect2.toShortString());
        float f1 = this.mFinishRects[pinchIndex].width();
        float f2 = this.mChildRects[pinchIndex].width();
        float f3 = f1 / f2;
        float f4 = this.mFinishRects[pinchIndex].height();
        float f5 = this.mChildRects[pinchIndex].height();
        float f6 = f4 / f5;
        int i43 = 0;

        while (i43 < i) {
            if (i43 != pinchIndex) {
                int i46 = this.mChildRects[i43].left;
                int i47 = this.mChildRects[pinchIndex].left;
                int i48 = i46 - i47;
                int i49 = this.mChildRects[i43].top;
                int i51 = i49 - this.mChildRects[pinchIndex].top;
                int i52 = (int) (i48 * f3);
                int i53 = (int) (i51 * f6);
                int i54 = this.mFinishRects[pinchIndex].left + i52;
                int i55 = this.mFinishRects[pinchIndex].top + i53;
                int i56 = this.mFinishRects[pinchIndex].right + i52;
                int i57 = this.mFinishRects[pinchIndex].bottom + i53;
                this.mFinishRects[i43].set(i54, i55, i56, i57);
            }

            i43++;
        }
    }

    private void setDeleteZoneState(final boolean paramBoolean) {
        //		Log.e(TAG,"setDeleteZoneState");
        this.mLauncher.getDeleteZone().setDragEnterForced(paramBoolean);
        this.mLauncher.getDeleteZone().invalidate();
    }

    /**
     * 完整
     *
     * @param pinchIndex
     */
    private void setOpenStartRect(final int pinchIndex) {
        // Log.e(TAG,"setOpenStartRect");
        int i = getChildCount();

        // this.getLocationOnScreen(this.mTmpLocation);
        // 目前这个值为 [0,25]。
        // Log.e(TAG,"mTmpLocation "+mTmpLocation[0]+" "+mTmpLocation[1]);
        // y 为 25.
        View cellLayout0 = this.mLauncher.getWorkspace().getChildAt(0);

        // this.mLauncher.getWorkspace().getLocationOnScreen(this.mTmpLocation);

        // i4 为50?
        // Log.e(TAG,"i4 "+i4);
        int i11 = 0;

        // 初始化 mStartRects.
        if (this.mStartRects == null || this.mStartRects.length != i) {
            this.mStartRects = new Rect[i];
            i11 = 0;

            while (i11 < i) {
                this.mStartRects[i11] = new Rect();
                i11++;
            }
        }

        // cellLayout0.getLeft() 为0 。
        int i12 = cellLayout0.getLeft() - this.mScreenBgDrawablePadding.left;

        int i13 = cellLayout0.getTop() - this.mScreenBgDrawablePadding.top;

        int i14 = cellLayout0.getLeft() + cellLayout0.getWidth()
                  + this.mScreenBgDrawablePadding.right;

        int i15 = cellLayout0.getTop() + cellLayout0.getHeight()
                  + this.mScreenBgDrawablePadding.bottom;

        // 设置当前屏幕的初始矩形的值.
        this.mStartRects[pinchIndex].set(i12, i13, i14, i15);

        // 宽的比例
        float f3 = this.mStartRects[pinchIndex].width() / this.mChildRects[pinchIndex]
                                                          .width();

        // 高的比例
        float f6 = this.mStartRects[pinchIndex].height() / this.mChildRects[pinchIndex]
                                                           .height();

        // //输出mChildRects 的值，调试用
        // Log.e(TAG,"############");
        // int h = 0;
        // while (h < i) {
        // Log.e(TAG,"mChildRects "+ h+" "+
        // this.mChildRects[h].toShortString());
        // h++;
        // }
        // Log.e(TAG,"############");
        //
        int i41 = 0;

        while (i41 < i) {
            if (i41 != pinchIndex) {
                // 每个矩形与当前矩形的水平方向的距离
                int i46 = this.mChildRects[i41].left
                          - this.mChildRects[pinchIndex].left;

                // 每个矩形与当前矩形的竖直方向的距离
                int i49 = this.mChildRects[i41].top
                          - this.mChildRects[pinchIndex].top;
                int i50 = (int) (i46 * f3);
                int i51 = (int) (i49 * f6);

                int i52 = this.mStartRects[pinchIndex].left + i50;
                int i53 = this.mStartRects[pinchIndex].top + i51;
                int i54 = this.mStartRects[pinchIndex].right + i50;
                int i55 = this.mStartRects[pinchIndex].bottom + i51;
                this.mStartRects[i41].set(i52, i53, i54, i55);
            }

            i41++;
        }
    }

    private void startDrag(final View view) {
//        Log.e(TAG, "startDrag " + view.toString());
        this.mTouchState = TOUCH_STATE_DRAGGING;
        this.mDraggingIndex = ((Integer) view.getTag()).intValue();
        this.mOriginDragIndex = this.mDraggingIndex;
        this.mDraggingView = view;
        this.mTouchedView = view;
        this.mDraggingView.buildDrawingCache();

        Bitmap localBitmap1 = this.mDraggingView.getDrawingCache();
        Matrix localMatrix = new Matrix();
        localMatrix.setScale(1.01F, 1.01F);
        this.mPressBitmap = Bitmap.createBitmap(localBitmap1, 0, 0,
                                                localBitmap1.getWidth(),
                                                localBitmap1.getHeight(),
                                                localMatrix, true);
        view.invalidate();
    }

    /**
     * 完整
     *
     * @param index
     */
    private void swapScreen(final int index) {
//    	Log.e(TAG,"last "+ (System.currentTimeMillis()-last));
//    	last= 	System.currentTimeMillis();
        View localView = this.mDraggingView;
        int i = indexOfChild(localView);
        Utilities.zOrderTweakMoveChild(this, i, index, true);
        onSwap(index);
//     	Log.e(TAG,"swapScreen  2");
//    	Log.e(TAG,"last "+ (System.currentTimeMillis()-last));
//        last= 	System.currentTimeMillis();
     	
    }
    
//    long last= System.currentTimeMillis();

    private void updateAppInfoInDatabase() {
    	new Thread()
    	{
    		@Override
    		public void run() {
    			   Workspace localWorkspace = mLauncher.getWorkspace();
    		        int i = localWorkspace.getChildCount();
    		        int j = 0;

    		        while (j < i) {
    		            ViewGroup localViewGroup = (ViewGroup) localWorkspace.getChildAt(j);
    		            int k = localViewGroup.getChildCount();
    		            int m = 0;
    		            while (m < k) {
    		                Object localObject = localViewGroup.getChildAt(m).getTag();
    		                if (localObject != null) {
    		                    ItemInfo localItemInfo = (ItemInfo) localObject;
    		                    if (localItemInfo.screen != j) {
    		                        localItemInfo.screen = j;
    		                        LauncherModel.updateItemInDatabase(mLauncher,
    		                                                           localItemInfo);
    		                    }
    		                }
    		                m++;
    		            }
    		            j++;
    		        }
    		        
//    		        Log.e(TAG,"updateAppInfoInDatabase  end");
    		}
    	}.start();
    	
     
    }

    private void updateTag() {
        int i = getChildCount();
        int j = 0;
        while (j < i) {
            View child = getChildAt(j);
            if (child.getTag() != ADD_BTN_TAG) {
                child.setTag(j);
            }
            j++;
        }
    }

    /**
     * 完整
     *
     * @param paramInt1
     * @param paramInt2
     * @param paramFloat
     */
    private void updateWallpaperOffset(final int paramInt1,
                                       final int paramInt2,
                                       final float paramFloat) {
        float f1 = 0.5F;

        if (this.mWorkspaceScreenCountOnOpen > 1) {
            float f2 = this.mWorkspaceScreenIndexOnOpen;
            float f3 = this.mWorkspaceScreenCountOnOpen - 1;
            f1 = f2 / f3;
        }

        float f4 = 0.5F;

        if (paramInt2 > 1) {
            float f5 = paramInt1;
            float f6 = paramInt2 - 1;
            f4 = f5 / f6;
        }

        float f7 = (f4 - f1) * paramFloat;
        float f8 = f1 + f7;
        Workspace localWorkspace = this.mLauncher.getWorkspace();
        float f9 = (this.mLauncher.getWorkspace().getChildCount() - 1) * f8;
        float f10 = this.mLauncher.getWorkspace().getWidth();
        int i = (int) (f9 * f10);
        localWorkspace.scrollTo(i, 0);

        IBinder localIBinder = getWindowToken();

        if (localIBinder != null) {
            this.mWallpaperManager.setWallpaperOffsets(localIBinder, f8, 0.0F);
        }
    }

    /**
     * 完整
     */
    class Animate implements Runnable {
        private Scroller mScroller;
        private TFAnimateEngine mAnimateEngine;
        private View mTargetView;
        private Rect[] mDestRects;
        private Rect[] mResultRects;
        private Rect[] mStartRects;
        private static final int PROGRESS_INT_MAX = 100;

        /**
         * Creates a new Animate object.
         */
        Animate() {
            this.mStartRects = new Rect[1];
            mStartRects[0] = new Rect();

            Rect[] arrayOfRect2 = new Rect[1];
            arrayOfRect2[0] = new Rect();
            this.mDestRects = arrayOfRect2;

            Rect[] arrayOfRect3 = new Rect[1];
            arrayOfRect3[0] = new Rect();
            this.mResultRects = arrayOfRect3;
            this.mAnimateEngine = new TFAnimateEngine();
            this.mScroller = new Scroller(getContext(),
                                          new DecelerateInterpolator());
        }

        public boolean isEnd() {
            if (!this.mScroller.computeScrollOffset()) {
                return true;
            }

            return false;
        }

        public void run() {
            boolean bool1 = this.mScroller.computeScrollOffset();
            int i = this.mScroller.getCurrX();
            Rect[] arrayOfRect1 = this.mStartRects;
            Rect[] arrayOfRect2 = this.mDestRects;
            Rect[] arrayOfRect3 = this.mResultRects;
            float f = i / 100.0F;
            this.mAnimateEngine.getRect(arrayOfRect1, arrayOfRect2,
                                        arrayOfRect3, f);

            View localView = this.mTargetView;

            if (bool1) {
                int j = this.mResultRects[0].left;
                int k = this.mResultRects[0].top;
                int m = this.mResultRects[0].right;
                int n = this.mResultRects[0].bottom;
                localView.layout(j, k, m, n);
                QuickViewWorkspace.this.invalidate();
                QuickViewWorkspace.this.post(this);

                return;
            } else {
                int i1 = this.mDestRects[0].left;
                int i2 = this.mDestRects[0].top;
                int i3 = this.mDestRects[0].right;
                int i4 = this.mDestRects[0].bottom;
                localView.layout(i1, i2, i3, i4);
                QuickViewWorkspace.this.invalidate();
            }
        }

        public void start(final View v, final Rect rect) {
            stop();
            this.mTargetView = v;
            v.getHitRect(this.mStartRects[0]);
            this.mDestRects[0].set(rect);
            this.mScroller.startScroll(0, 0, PROGRESS_INT_MAX, 0, 300);
            QuickViewWorkspace.this.post(this);
        }

        public void stop() {
            QuickViewWorkspace.this.removeCallbacks(this);
        }
    }

    class Defines {
        public static final int TWO_FINGER_ACTION_END_DISTANCE = 500;
        public static final int TWO_FINGER_ACTION_START_DISTANCE = 100;
        public static final int TWO_FINGER_ACTION_TRIGGER_DISTANCE = 400;
    }
}
